<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../include/admincontent.jsp" %>
<link rel="stylesheet" href="../../resources/js/plugins/layui/css/layui.css" />
<script src="../../resources/js/plugins/layui/layui.all.js" type="text/javascript"></script>
<div id="Content">
    <form id="excelValid" method="post"  action="/ExcelImport/ImportExcel" enctype="multipart/form-data">
        <%--<input type="hidden" name="pid" value="${pid}"/>--%>
        <%--<input type="hidden" name="fid" value="${fid}"/>--%>
        <%--<input type="hidden" name="deptcode" value="${deptcode}"/>--%>
            ${searchdata}
        <div class="help">
            <b>注意：</b><br>
            1、数据导入请上传excel格式(<b>后缀为：xls或xlsx</b>)<br/>
            2、系统自动识别身份证号(<b>首行列中以身份证开始的列</b>)<br/>
            3、<span style="color: red">面试</span>和<span style="color: red">素质测试</span>识别列名为<b><span style="color: red">成绩、结果、备注/评分规则</span></b><br/>
            4、通过状态为<b><span style="color: red">通过、已通过、合格</span></b><br/>
            5、不通过状态为<b><span style="color: red">不通过、未通过、不合格</span></b><br/>
            6、其他环节识别<span style="color: red">结果、备注</span>，成绩数据将不会保存。

        </div>
        <table class="treeTable searchform">
            <thead>
            <tr>
                <td width="80">Excel文件：</td>
                <td>
                    <div><input type="file" name="excel" datatype="*" nullmsg="请选择Excel文件"/></div>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                   <%-- data-type="loading"--%>
                    <button class="layui-btn site-demo-active" id="btn_import" type="submit">导入数据</button>
                  <%--  <button type="submit" id="btn_import" class="op">导入数据</button>--%>
                </td>
            </tr>
            </thead>
        </table>
    </form>
</div>
<%--<div class="layui-progress layui-progress-big" lay-showpercent="true" lay-filter="excelprogress">
    <div class="layui-progress-bar layui-bg-red" lay-percent="0%"></div>
</div>--%>
<div class="layui-progress" lay-showpercent="true">
    <div class="layui-progress-bar" lay-percent="20%"></div>
</div>
<script src="/resources/js/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript">
    var time;
    var lindex;
    var DISABLED = 'layui-btn-disabled';
    layui.use('element', function(){
        var element = layui.element;
    });
    layui.use('element', function(){
        var $ = layui.jquery
            ,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
        var downurl="";
        //触发事件
        var active = {
           loading: function(othis){

                lindex=  layer.alert('  <div><div id="importResult"></div><div class="layui-progress layui-progress-big" lay-showpercent="true" lay-filter="excelprogress">\n'
                    +'    <div class="layui-progress-bar layui-bg-red" lay-percent="0%"></div>\n'
                    +'</div></div>',{"btn":false,"title":"导入中请耐心等待"});
                if(othis.hasClass(DISABLED)) return;

                //模拟loading
                var n = 0;
                timer = setInterval(function(){
                    $.ajax({
                        url:'/ExcelImport/getProcess',
                        dataType:'JSON',
                        type:'POST',
                        success:function (json) {
                            if (json.datas!=null){
                            var totalNum=json.datas.totalNum;
                            var successNum=json.datas.successNum;
                            var errorNum=json.datas.errorNum;
                             n=((successNum+errorNum)/totalNum)*100;
                            //n = n + Math.random()*10|0;
                            if(n>=100){
                                n = 100;
                                clearInterval(timer);
                                othis.removeClass(DISABLED);
                                layer.close(lindex);
                                layer.alert("导入完成！"+successNum+"条数据导入成功！"+errorNum+"条数据导入失败！"
                                    ,{"btn":['下载结果文件', '关闭']
                                        ,yes:function () {
                                           if(downurl!=""){
                                               location.href=downurl;
                                           }
                                        }
                                    });
                            }
                            $('#importResult').empty();
                            $('#importResult').append('<span>共'+totalNum+'条数据。'+successNum+'条数据导入成功，'+errorNum+'条数据导入失败！</span>');
                            element.progress('excelprogress', n+'%');
                            }
                        }
                    });


                }, 1000);

                othis.addClass(DISABLED);
            }
        };
    });

    $("#excelValid").Validform({
        tiptype:function(msg){
            if(msg == "请选择Excel文件")
                layer.msg("请先选择需要导入的EXCEL文件！", {icon: 2});
        },
        ajaxPost: true,
        beforeSubmit: function (curform) {
           /* var othis = $('#btn_import'), type = $('#btn_import').data('type');
            active[type] ? active[type].call($('#btn_import'), othis) : '';*/
            curform.ajaxSubmit({
                type: 'post',
               // dataType: 'json',
                success: function (data) {
                    //data = $.parseJSON($(data).text());
                    if (data.state){
                        //clearInterval(timer);
                        /*downurl=data.url;

                        parent.frames["mainiframe"].contentWindow.getList();*/
                        // $.Showmsg(data.Message);
                        // layer.alert(data.message);
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.alert(data.Message, {icon: 1,time:2000});
                    } else {
                        /*clearInterval(timer);
                        layer.alert(data.message);
                        layer.close(lindex);
                        $('#btn_import').removeClass(DISABLED)*/
                        //parent.$.Showmsg(data.Message);
                        parent.layer.alert(data.Message, {icon: 2,time:2000});
                    }
                }
            });
            return false;
        }
    });
/*    $('#btn_import').on('click', function(){
        $("#excelValid").submit();
        //表单提交
        return false;
    });*/
</script>
</body>
</html>